package com.whfc.ms.api.fse.controller;


import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.fse.param.FseResumeParam;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fse.service.MsFseResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @DESCRIPTION 特种设备履历
 * @AUTHOR hw
 * @DATE 2020/08/10
 */
@RestController
@RequestMapping("/ms/api/resume")
public class FseResumeController extends BaseController {

    @Autowired
    private MsFseResumeService msFseResumeService;

    @GetMapping(value = "/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize,
                       @RequestParam("fseId")Integer fseId,
                       @RequestParam("resumeType")Integer resumeType) {
        logger.info("特种设备履历列表,loginer:{},pageNum:{},pageSize:{},fseId:{},resumeType:{}",
                user.getUsername(), pageNum, pageSize, fseId, resumeType);
        PageData<FseResumeParam> pageData = msFseResumeService.list(fseId, resumeType,pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody @Validated FseResumeParam request) {
        logger.info("添加特种设备履历,loginer:{},param:{}", user.getUsername(), request.toString());
        msFseResumeService.add(request);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody @Validated FseResumeParam request) {
        logger.info("修改特种设备履历,loginer:{},param:{}", user.getUsername(), request.toString());
        msFseResumeService.edit(request);
        return ResultUtil.success();
    }

    @PostMapping("/del/{resumeId}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @PathVariable("resumeId") Integer resumeId) {
        logger.info("添加特种设备履历,loginer:{},resumeId:{}", user.getUsername(), resumeId);
        msFseResumeService.del(resumeId);
        return ResultUtil.success();
    }


    @PostMapping("upload")
    public Result upload(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                         @RequestParam(value = "file") MultipartFile file){
        logger.info("特种设备履历上传,loginer:{}", user.getUsername());
        OssPathDTO data = msFseResumeService.upload(file);
        return ResultUtil.success(data);
    }
}
